package com.charging.business.initial;

import com.charging.business.constants.JinGbMinFeeThread;
import com.charging.business.constants.LibraryThread;
import com.charging.business.constants.QinGbMinFeeThread;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * @author JerryLu
 * @date 2024/8/6 16:17
 * @description 初始化服务启动
 */
@Component
@Slf4j
//@Order(1)
public class LocalTransaction implements CommandLineRunner {
    private static final Logger logger = LoggerFactory.getLogger(LocalTransaction.class);

    private final LibraryThread feeThread;

//    private final QinGbMinFeeThread qinFeeThread;

    private final JinGbMinFeeThread jinFeeThread;

    public LocalTransaction(LibraryThread feeThread,
//                            QinGbMinFeeThread qinFeeThread,
                            JinGbMinFeeThread jinFeeThread) {
        this.feeThread = feeThread;
//        this.qinFeeThread = qinFeeThread;
        this.jinFeeThread = jinFeeThread;
    }

    @Override
    public void run(String... args) throws Exception {
        //开始启动相关服务
//        Future<String> future1 = this.qinFeeThread.execute();
//        Future<String> future2 = this.jinFeeThread.execute();
//        Future<String> future3 = this.feeThread.execute();
        this.jinFeeThread.execute();
        this.feeThread.execute();

        // 等待异步方法完成
//        try {
//            String result1 = future1.get(); // 等待第一进程完成
//            String result2 = future2.get(); // 等待第二进程完成
//            String result3 = future3.get(); // 等待第三进程完成
//        } catch (InterruptedException | ExecutionException e) {
//            logger.warn("计费服务初始化异常,{}", e.getMessage());
//            e.printStackTrace();
//        }
    }
}
